//
//  LZTableHeaderView.m
//  LZCartViewController
//
//  Created by Artron_LQQ on 16/5/31.
//  Copyright © 2016年 Artup. All rights reserved.
//

#import "LZTableHeaderView.h"
#import "LZConfigFile.h"

@interface LZTableHeaderView ()

@property (strong,nonatomic)UILabel *titleLabel;
@property (strong,nonatomic)UIButton *button;
@property (strong,nonatomic)UIImageView *logoImage;

@property (strong,nonatomic)UILabel *storeNameLabel;
@property (strong,nonatomic)UIButton *isNewbutton;
@end
@implementation LZTableHeaderView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupUI];
    }
    
    return self;
}

- (void)setupUI {
    
//    self.contentView.backgroundColor = [UIColor AxcUI_colorWithHexCode:@"#ebebeb"];za
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:button];
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(25);
        make.bottom.mas_equalTo(-10);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(30);
    }];
//    button.frame = CGRectMake(25, 10, 50, 30);
    
    [button setImage:[UIImage imageNamed:@"cart_unSelect_btn"] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:@"cart_selected_btn"] forState:UIControlStateSelected];
    [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    
    self.button = button;
    
    UILabel *label = [[UILabel alloc]init];
    
    [self.contentView addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(115);
        make.bottom.mas_equalTo(-7.5);
        make.width.mas_equalTo(KScreenWidth -130);
        make.height.mas_equalTo(40);
    }];
    label.numberOfLines=2;
//    label.frame = CGRectMake(70, 10, LZSCREEN_WIDTH - 100, 30);
     label.font = [UIFont systemFontOfSize:14];
     self.titleLabel = label;
   
    UIImageView * imageView = [[UIImageView alloc]init];
    imageView.contentMode = UIViewContentModeScaleAspectFill;
    imageView.clipsToBounds = YES;
    imageView.layer.masksToBounds = YES;
    imageView.layer.cornerRadius = 3;
    [self.contentView addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(70);
        make.bottom.mas_equalTo(-7.5);
        make.width.mas_equalTo(35);
        make.height.mas_equalTo(35);
    }];
    self.logoImage = imageView;
    
    UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:button2];
    [button2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(5);
        make.top.mas_equalTo(10);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(30);
    }];
    //    button.frame = CGRectMake(25, 10, 50, 30);
    
    [button2 setImage:[UIImage imageNamed:@"cart_unSelect_btn"] forState:UIControlStateNormal];
    [button2 setImage:[UIImage imageNamed:@"cart_selected_btn"] forState:UIControlStateSelected];
    [button2 addTarget:self action:@selector(buttonStoreClick:) forControlEvents:UIControlEventTouchUpInside];
    self.isNewbutton = button2;
    
    UILabel *label2 = [[UILabel alloc]init];
    [self.contentView addSubview:label2];
    [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(50);
        make.top.mas_equalTo(10);
        make.width.mas_equalTo(KScreenWidth-140);
        make.height.mas_equalTo(30);
    }];
    //    label.frame = CGRectMake(70, 10, LZSCREEN_WIDTH - 100, 30);
    label2.font = [UIFont systemFontOfSize:14];
    self.storeNameLabel = label2;

}
-(void)setIsNewStore:(BOOL)isNewStore
{
    if (isNewStore) {
        self.isNewbutton.hidden = NO;
        self.storeNameLabel.hidden = NO;
    }else{
        self.isNewbutton.hidden = YES;
        self.storeNameLabel.hidden = YES;
    }
}
- (void)buttonClick:(UIButton*)button {
    button.selected = !button.selected;
    
    if (self.lzClickBlock) {
        self.lzClickBlock(button.selected);
    }
}
- (void)buttonStoreClick:(UIButton*)button {
    button.selected = !button.selected;
    
    if (self.lzStoreClickBlock) {
        self.lzStoreClickBlock(button.selected);
    }
}

- (void)setSelect:(BOOL)select {
    
    self.button.selected = select;
    _select = select;
}
- (void)setStoreSelect:(BOOL)select {
    
    self.isNewbutton.selected = select;
    _storeSelect = select;
}

- (void)setTitle:(NSString *)title {
    self.titleLabel.text = title;
    _title = title;
}
-(void)setStoreName:(NSString *)storeName
{
    self.storeNameLabel.text = storeName;
    _storeName = storeName;
}
-(void)setImageUrl:(NSString *)imageUrl
{
    [self.logoImage sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:mImageByName(@"")];
    _imageUrl = imageUrl;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
